package com.nc.menu.controller;

import com.nc.menu.service.RedisService;
import com.plug.result.RetResponse;
import com.plug.result.RetResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
@Api
@RestController
@RequestMapping("GatewayController")
public class GatewayController {
    @Autowired
    private RedisService redisService;

    @ApiOperation("获得网关配置")
    @GetMapping("rule")
    public RetResult getRule() {
        return RetResponse.makeOKRsp(redisService.get("gateway"));
    }

    @PostMapping("rule")
    @ApiOperation("设置网关")
    public RetResult setRule(@RequestBody String val) {
        try {
            JSONArray.fromObject(val);
            return RetResponse.makeOKRsp(redisService.set("gateway", val));
        } catch (Exception e) {
            return RetResponse.makeErrRsp("请输入正确的格式");
        }
    }

}
